package com.server;

import java.io.IOException;
import java.sql.SQLException;

import java.util.*;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.Helper.*;

public class FlightHackServlet extends CustomerServlet
{
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException
	{
		ConnectDB();
		String username = req.getParameter("username");
		String flightID = req.getParameter("flightID");
		int point;
		int numRes;
		int numPointToClaim;
		String msg = null;
		
		
		try 
		{
			FlightHelper.Setup(connection);
			CustomerHelper.Setup(connection);
			ReservationHelper.Setup(connection, username);
			
			if (req.getParameter("arrive") != null)
			{
				FlightHelper.MarkArrived(flightID);
			}
			else if (req.getParameter("ontime") != null)
			{
				FlightHelper.MarkOnTime(flightID);
			}
			else
			{
				System.out.println("you shouldn't see this");
			}
						
			msg = flightID + " has arrived.";
			point = CustomerHelper.GetSelectedCustomer(username).point;
			
			numRes = ReservationHelper.GetReservationList().size();
			numPointToClaim = ReservationHelper.GetNumPointsToClaim();
			
			req.setAttribute("username", username);
			req.setAttribute("point", point);
			req.setAttribute("msg", msg);
			req.getRequestDispatcher("index_loggedin.jsp").forward(req, resp);
		} 
		catch (SQLException e) 
		{
			e.printStackTrace();
		}
	}

}

